package com.ruoyi.web.controller.apply;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.apply.domain.ApplyFor;
import com.ruoyi.apply.service.IApplyForService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 提交申请Controller
 *
 * @author ruoyi
 * @date 2023-12-01
 */
@RestController
@RequestMapping("/apply/manage")
public class ApplyForController extends BaseController
{
    @Autowired
    private IApplyForService applyForService;

    /**
     * 查询提交申请列表
     */
    @PreAuthorize("@ss.hasPermi('apply:manage:list')")
    @GetMapping("/list")
    public TableDataInfo list(ApplyFor applyFor)
    {
        startPage();
        List<ApplyFor> list = applyForService.selectApplyForList(applyFor);
        return getDataTable(list);
    }

    /**
     * 导出提交申请列表
     */
    @PreAuthorize("@ss.hasPermi('apply:manage:export')")
    @Log(title = "提交申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ApplyFor applyFor)
    {
        List<ApplyFor> list = applyForService.selectApplyForList(applyFor);
        ExcelUtil<ApplyFor> util = new ExcelUtil<ApplyFor>(ApplyFor.class);
        util.exportExcel(response, list, "提交申请数据");
    }

    /**
     * 获取提交申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('apply:manage:query')")
    @GetMapping(value = "/{applyId}")
    public AjaxResult getInfo(@PathVariable("applyId") Long applyId)
    {
        return success(applyForService.selectApplyForByApplyId(applyId));
    }

    /**
     * 新增提交申请
     */
    @PreAuthorize("@ss.hasPermi('apply:manage:add')")
    @Log(title = "提交申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ApplyFor applyFor)
    {
        applyFor.setUserId(SecurityUtils.getUsername());
        return toAjax(applyForService.insertApplyFor(applyFor));
    }

    /**
     * 修改提交申请
     */
    @PreAuthorize("@ss.hasPermi('apply:manage:edit')")
    @Log(title = "提交申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ApplyFor applyFor)
    {
        return toAjax(applyForService.updateApplyFor(applyFor));
    }

    /**
     * 删除提交申请
     */
    @PreAuthorize("@ss.hasPermi('apply:manage:remove')")
    @Log(title = "提交申请", businessType = BusinessType.DELETE)
    @DeleteMapping("/{applyIds}")
    public AjaxResult remove(@PathVariable Long[] applyIds)
    {
        return toAjax(applyForService.deleteApplyForByApplyIds(applyIds));
    }
}
